//
//  WindView.m
//  ExploreWorld
//
//  Created by dlios on 15/7/15.
//  Copyright (c) 2015年 chenlin. All rights reserved.
//

#import "WindView.h"

@implementation WindView

- (void)dealloc
{
    [self.pile release];
    [self.leaf release];
    [self.sk_fl release];
    [self.sk_fs release];
    [self.sk_fx release];
    [super dealloc];
}

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        [self createMyWindView];
    }
    return self;
}


- (void)createMyWindView
{
    float wid = self.frame.size.width;
    float hei = self.frame.size.height / 8;
    
    //风扇桩
    self.pile = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, 10, hei * 3)];
    [self.pile setCenter:CGPointMake(wid / 4, hei * 6)];
    [self.pile setImage:[UIImage imageNamed:@"bigpole@3x.png"]];
    [self addSubview:self.pile];
    
  //风扇叶
    self.leaf = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, hei * 3, hei * 3)];
    [self.leaf setCenter:CGPointMake(wid / 4, hei * 4)];
    [self.leaf setImage:[UIImage imageNamed:@"blade_big_blur@3x.png"]];
    [self AddAnimationForLeaf:self.leaf WithSK_FL:self.sk_fl.text];
    [self addSubview:self.leaf];
  
    
    //风力
    self.sk_fl = [[UILabel alloc]initWithFrame:CGRectMake(wid / 2 + 10, hei * 4, wid / 2 - 10, hei)];
    [self addSubview:self.sk_fl];
    [self.sk_fl setFont:[UIFont systemFontOfSize:12]];
    [self.sk_fl setTextColor:[UIColor redColor]];
    
    
    //风向
    self.sk_fx = [[UILabel alloc]initWithFrame:CGRectMake(wid / 2 + 10, hei * 5, wid / 2 - 10, hei )];
    [self addSubview: self.sk_fx];
    [self.sk_fx setFont:[UIFont systemFontOfSize:12]];
    [self.sk_fx setTextColor:[UIColor greenColor]];
    
    
    //风速
    self.sk_fs =  [[UILabel alloc]initWithFrame:CGRectMake(wid / 2 + 10, hei * 6, wid / 2 - 10, hei )];
    [self addSubview:self.sk_fs];
    [self .sk_fs setFont:[UIFont systemFontOfSize:12]];
    [self.sk_fs setTextColor:[UIColor brownColor]];
    
 
}



//为枫叶添加旋转动画
- (void)AddAnimationForLeaf:(UIView * )leafView  WithSK_FL:(NSString *)sk_fl
{
    float x =  [sk_fl floatValue];
    
    CABasicAnimation *theAnimation;

    theAnimation=[CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    theAnimation.toValue = [NSNumber numberWithFloat:M_PI * 2.0];
    theAnimation.duration = 1;
    theAnimation.repeatCount = 1000000000;
    theAnimation.removedOnCompletion = YES;
    theAnimation.cumulative = NO;
    [leafView.layer addAnimation:theAnimation forKey:@"animateTransform"];
   
}





@end
